classes = [
    {"name": "abyss", "age": 25, "grade": "A"},
    {"name": "kin", "age": 23, "grade": "B"},
    {"name": "tian", "age": 24, "grade": "B"},
    {"name": "hun", "age": 26, "grade": "A"},
    {"name": "exe", "age": 21, "grade": "A"}
]


def sort_for_lambda():
    return sorted(classes, key=lambda d: d['age'])


def sort_for_age(d):
    return d['age']


def sort_for_normal_func():
    return sorted(classes, key=sort_for_age, reverse=True)


def map_age_add(d):
    d['age'] += 1
    return d


def fibonacci(n):
    try:
        n = int(n)
        if n <= 1:
            return n
        return fibonacci(n - 1) + fibonacci(n - 2)
    except ValueError:
        print('参数类型不正确')


if __name__ == "__main__":
    print(f'匿名函数排序: {sort_for_lambda()}')
    print(f'常规函数排序: {sort_for_normal_func()}')
    before_map_classes = map(map_age_add, classes)
    print(f'age + 1之前: {classes}')
    print(f'age + 1之后: {list(before_map_classes)}')
    before_filter_classes = filter(lambda d: d['grade'] != 'A', classes)
    print(f'过滤之前: {classes}')
    print(f'过滤之后: {list(before_filter_classes)}')
    for i in range(10):
        print(fibonacci(i), end=' ')
